﻿using System.Linq;
using System.Collections.Generic;

namespace Songhay.Web.Mvc.Models
{
    using Songhay.Extensions;

    /// <summary>
    /// Defines the data for embedding a Silverlight Client.
    /// </summary>
    public class SilverlightModel
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="SilverlightModel"/> class.
        /// </summary>
        public SilverlightModel()
        {
            this.ClientApplicationProperties = new Dictionary<string, string>();
            this.InitializationParametersDictionary = new Dictionary<string, string>();
            this.Dimensions = new Size { Width = "100%", Height = "100%" };
        }

        /// <summary>
        /// Gets or sets the color of the background.
        /// </summary>
        /// <value>The color of the background.</value>
        public string BackgroundColor { get; set; }

        /// <summary>
        /// Gets or sets the client application properties.
        /// </summary>
        /// <value>The client application properties.</value>
        public Dictionary<string, string> ClientApplicationProperties { get; set; }

        /// <summary>
        /// Gets or sets the dimensions.
        /// </summary>
        /// <value>The dimensions.</value>
        public Size Dimensions { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether to enable HTML access.
        /// </summary>
        /// <value><c>true</c> if enable HTML access; otherwise, <c>false</c>.</value>
        public bool EnableHtmlAccess { get; set; }

        /// <summary>
        /// Gets the initialization parameters.
        /// </summary>
        /// <value>The initialization parameters.</value>
        public string InitializationParameters
        {
            get
            {
                if(this.InitializationParametersDictionary.Count == 0) return null;
                string s = null;
                this.InitializationParametersDictionary.ForEachInEnumerable(pair =>
                {
                    s += string.IsNullOrEmpty(s) ?
                        string.Format("{0}={1}", pair.Key, pair.Value)
                        :
                        string.Format(",{0}={1}", pair.Key, pair.Value);
                });
                return s;
            }
        }

        /// <summary>
        /// Gets or sets the initialization parameters dictionary.
        /// </summary>
        /// <value>The initialization parameters dictionary.</value>
        public Dictionary<string, string> InitializationParametersDictionary { get; private set; }

        /// <summary>
        /// Gets or sets the minimum runtime version.
        /// </summary>
        /// <value>The minimum runtime version.</value>
        public string MinimumRuntimeVersion { get; set; }

        /// <summary>
        /// Gets or sets the runtime version.
        /// </summary>
        /// <value>The runtime version.</value>
        public string RuntimeVersion { get; set; }

        /// <summary>
        /// Gets or sets the source.
        /// </summary>
        /// <value>The source.</value>
        public string Source { get; set; }
    }
}
